using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace IWS.Lib.SingleSignOnServer
{
	/// <summary>
	/// Strongly-typed collection for the Service class.
	/// </summary>
	[Serializable]
	public partial class ServiceCollection : ActiveList<Service, ServiceCollection> 
	{	   
		public ServiceCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the sso_Service table.
	/// </summary>
	[Serializable]
	public partial class Service : ActiveRecord<Service>
	{
		#region .ctors and Default Settings
		
		public Service()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Service(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Service(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Service(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("sso_Service", TableType.Table, DataService.GetInstance("Default"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarId = new TableSchema.TableColumn(schema);
				colvarId.ColumnName = "ID";
				colvarId.DataType = DbType.String;
				colvarId.MaxLength = 50;
				colvarId.AutoIncrement = false;
				colvarId.IsNullable = false;
				colvarId.IsPrimaryKey = true;
				colvarId.IsForeignKey = false;
				colvarId.IsReadOnly = false;
				colvarId.DefaultSetting = @"";
				colvarId.ForeignKeyTableName = "";
				schema.Columns.Add(colvarId);
				
				TableSchema.TableColumn colvarKeyFile = new TableSchema.TableColumn(schema);
				colvarKeyFile.ColumnName = "KeyFile";
				colvarKeyFile.DataType = DbType.String;
				colvarKeyFile.MaxLength = 50;
				colvarKeyFile.AutoIncrement = false;
				colvarKeyFile.IsNullable = true;
				colvarKeyFile.IsPrimaryKey = false;
				colvarKeyFile.IsForeignKey = false;
				colvarKeyFile.IsReadOnly = false;
				colvarKeyFile.DefaultSetting = @"";
				colvarKeyFile.ForeignKeyTableName = "";
				schema.Columns.Add(colvarKeyFile);
				
				TableSchema.TableColumn colvarLastActiveDate = new TableSchema.TableColumn(schema);
				colvarLastActiveDate.ColumnName = "LastActiveDate";
				colvarLastActiveDate.DataType = DbType.DateTime;
				colvarLastActiveDate.MaxLength = 0;
				colvarLastActiveDate.AutoIncrement = false;
				colvarLastActiveDate.IsNullable = true;
				colvarLastActiveDate.IsPrimaryKey = false;
				colvarLastActiveDate.IsForeignKey = false;
				colvarLastActiveDate.IsReadOnly = false;
				colvarLastActiveDate.DefaultSetting = @"";
				colvarLastActiveDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastActiveDate);
				
				TableSchema.TableColumn colvarExpirationDate = new TableSchema.TableColumn(schema);
				colvarExpirationDate.ColumnName = "ExpirationDate";
				colvarExpirationDate.DataType = DbType.DateTime;
				colvarExpirationDate.MaxLength = 0;
				colvarExpirationDate.AutoIncrement = false;
				colvarExpirationDate.IsNullable = true;
				colvarExpirationDate.IsPrimaryKey = false;
				colvarExpirationDate.IsForeignKey = false;
				colvarExpirationDate.IsReadOnly = false;
				colvarExpirationDate.DefaultSetting = @"";
				colvarExpirationDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarExpirationDate);
				
				TableSchema.TableColumn colvarCreateDate = new TableSchema.TableColumn(schema);
				colvarCreateDate.ColumnName = "CreateDate";
				colvarCreateDate.DataType = DbType.DateTime;
				colvarCreateDate.MaxLength = 0;
				colvarCreateDate.AutoIncrement = false;
				colvarCreateDate.IsNullable = true;
				colvarCreateDate.IsPrimaryKey = false;
				colvarCreateDate.IsForeignKey = false;
				colvarCreateDate.IsReadOnly = false;
				colvarCreateDate.DefaultSetting = @"";
				colvarCreateDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreateDate);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Default"].AddSchema("sso_Service",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("Id")]
		public string Id 
		{
			get { return GetColumnValue<string>("ID"); }

			set { SetColumnValue("ID", value); }

		}

		  
		[XmlAttribute("KeyFile")]
		public string KeyFile 
		{
			get { return GetColumnValue<string>("KeyFile"); }

			set { SetColumnValue("KeyFile", value); }

		}

		  
		[XmlAttribute("LastActiveDate")]
		public DateTime? LastActiveDate 
		{
			get { return GetColumnValue<DateTime?>("LastActiveDate"); }

			set { SetColumnValue("LastActiveDate", value); }

		}

		  
		[XmlAttribute("ExpirationDate")]
		public DateTime? ExpirationDate 
		{
			get { return GetColumnValue<DateTime?>("ExpirationDate"); }

			set { SetColumnValue("ExpirationDate", value); }

		}

		  
		[XmlAttribute("CreateDate")]
		public DateTime? CreateDate 
		{
			get { return GetColumnValue<DateTime?>("CreateDate"); }

			set { SetColumnValue("CreateDate", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varId,string varKeyFile,DateTime? varLastActiveDate,DateTime? varExpirationDate,DateTime? varCreateDate)
		{
			Service item = new Service();
			
			item.Id = varId;
			
			item.KeyFile = varKeyFile;
			
			item.LastActiveDate = varLastActiveDate;
			
			item.ExpirationDate = varExpirationDate;
			
			item.CreateDate = varCreateDate;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(string varId,string varKeyFile,DateTime? varLastActiveDate,DateTime? varExpirationDate,DateTime? varCreateDate)
		{
			Service item = new Service();
			
				item.Id = varId;
				
				item.KeyFile = varKeyFile;
				
				item.LastActiveDate = varLastActiveDate;
				
				item.ExpirationDate = varExpirationDate;
				
				item.CreateDate = varCreateDate;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string Id = @"ID";
			 public static string KeyFile = @"KeyFile";
			 public static string LastActiveDate = @"LastActiveDate";
			 public static string ExpirationDate = @"ExpirationDate";
			 public static string CreateDate = @"CreateDate";
						
		}

		#endregion
	}

}

